"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
var app = getApp();
exports.default = Page({
  data: {
    val: 0
  },
  onLoad: function onLoad(e) {
    var _this = this;
    var money = e.money;
    var apply = wx.getStorageSync("info").apply;
    var openid = wx.getStorageSync("openid");
    _this.setData({
      openid: openid,
      money: money,
      apply: apply
    });
  },
  pay: function pay(e) {
    var _this = this;
    var money = _this.data.money;
    var val = parseInt(e.detail.value.val);
    if (val > 0) {
      if (money >= val) {
        wx.request({
          url: app.globalData.host,
          data: {
            mod: "record",
            act: "apply",
            ssid: _this.data.openid,
            price: val
          },
          method: "post", // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success: function success(res) {
            // success
            console.log(res);
            wx.showToast({
              title: res.data.txt,
              icon: 'none',
              duration: 1000,
              mask: false
            });
            //let ret = res.data.ret;
            /*if (ret != -1) {
              let oid = res.data.info.oid;
              let amount = res.data.info.amount;
              let openid = _this.data.openid;
              wx.request({
                url:
                  app.globalData.WxHost +
                  "ssid=" +
                  openid +
                  "&mid=" +
                  oid +
                  "&money=" +
                  amount,
                success: function(response) {
                  //console.log(response);
                  wx.requestPayment({
                    appId: response.data.appId,
                    nonceStr: response.data.nonceStr,
                    timeStamp: response.data.timeStamp,
                    package: response.data.package,
                    signType: response.data.signType,
                    paySign: response.data.paySign,
                    success: function(result) {
                      //console.log(result);
                      _this.setData(
                        {
                          mid: ""
                        },
                        () => {
                          wx.showToast({
                            title: "购买成功！",
                            icon: "none",
                            duration: 1000,
                            mask: false
                          });
                        }
                      );
                    },
                    fail: function(result) {
                      //console.log(result)
                      wx.showToast({
                        title: "支付失败！",
                        icon: "none",
                        duration: 1000,
                        mask: false
                      });
                    },
                    complete: function() {
                      // complete
                    }
                  });
                }
              });
            } else {
              wx.showToast({
                title: res.data.txt,
                icon: "none",
                duration: 1000,
                mask: false
              });
            }*/
          }
        });
      } else {
        wx.showToast({
          title: "余额不足！",
          icon: "none",
          duration: 1000,
          mask: false
        });
      }
    } else {
      wx.showToast({
        title: "提现金额不正确！",
        icon: "none",
        duration: 1000,
        mask: false
      });
    }
  }
});